package com.linq.cool.system.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linq.cool.common.core.domain.BaseEntity;
import com.linq.cool.common.core.utils.annotation.TreeEntity;
import com.linq.cool.common.core.utils.annotation.TreeField;
import com.linq.cool.common.core.utils.enums.FieldType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yqlin
 * @Date: 2020/12/29 15:26
 * @Description: 菜单权限表
 * @Version: 1.0.0
 */
@EqualsAndHashCode(callSuper = true)
@TreeEntity
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
@TableName(value = "sys_menu")
public class SysMenu extends BaseEntity {

    @TreeField(fieldType = FieldType.ID)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 菜单名称
     */
    @NotBlank(message = "菜单名称不能为空")
    @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
    @TableField(value = "`name`")
    private String name;

    /**
     * 父菜单ID
     */
    @TreeField(fieldType = FieldType.PID)
    @TableField(value = "parent_id")
    private Long parentId;

    /**
     * 显示顺序
     */
    @NotNull(message = "显示顺序不能为空")
    @TableField(value = "sort")
    private Integer sort;

    /**
     * 路由地址
     */
    @Size(min = 0, max = 200, message = "路由地址不能超过200个字符")
    @TableField(value = "`path`")
    private String path;

    /**
     * 组件路径
     */
    @Size(min = 0, max = 200, message = "组件路径不能超过255个字符")
    @TableField(value = "component")
    private String component;

    /**
     * 是否为外链（0:否 1:是）
     */
    @TableField(value = "is_frame")
    private Integer isFrame;

    /**
     * 是否缓存（1:缓存 0:不缓存）
     */
    @TableField(value = "is_cache")
    private Integer isCache;

    /**
     * 菜单状态（1:显示 0:隐藏）
     */
    @TableField(value = "is_visible")
    private Integer isVisible;

    /**
     * 菜单类型（0:目录 1:菜单 2:按钮）
     */
    @NotNull(message = "菜单类型不能为空")
    @TableField(value = "`type`")
    private Integer type;

    /**
     * 菜单状态（0:正常 1:停用）
     */
    @TableField(value = "`status`")
    private Integer status;

    /**
     * 权限标识
     */
    @Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符")
    @TableField(value = "perm_code")
    private String permCode;

    /**
     * 菜单图标
     */
    @TableField(value = "icon")
    private String icon;

    /**
     * 备注
     */
    @TableField(value = "remark")
    private String remark;

    /**
     * 子菜单
     */
    @TreeField(fieldType = FieldType.CHILD)
    @TableField(exist = false)
    private List<SysMenu> children = new ArrayList<>();

}